//
//  AppDelegate.swift
//  weibo
//
//  Created by 王旭 on 16/4/16.
//  Copyright © 2016年 王旭. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
        //注册通知
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeRootVC:", name: WXChangeRootVCNotification, object: nil)
        
        window = UIWindow.init(frame: UIScreen.mainScreen().bounds)
        window?.rootViewController = WXUserAccountViewModel.sharedUserAccountViewModel.isLogin ? WXWelcomeViewController() : WXMainViewController()
        window?.makeKeyAndVisible()
  
        return true
    }
    
    func changeRootVC(noti:NSNotification) {
        print("通知中心接收到通知,经过逻辑判断切换控制器")
        if noti.object != nil {
            //来自welcome控制器的通知
            window?.rootViewController = WXMainViewController()
        }else{
            //来自OAuth控制器的通知
            window?.rootViewController = WXWelcomeViewController()
        }
    }
    
    deinit{
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    
}

